# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=flac
pkgver=1.4.3
pkgrel=1
pkgdesc="Free Lossless Audio Codec"
url="https://xiph.org/flac/"
arch="all"
license="BSD-3-Clause AND GPL-2.0-or-later"
options="!check" # Tests are infinite
subpackages="$pkgname-dev $pkgname-libs libflac libflac++:libpp $pkgname-doc"
makedepends="cmake libogg-dev !libiconv samurai"
source="https://downloads.xiph.org/releases/flac/flac-$pkgver.tar.xz"

# secfixes:
#   1.3.4-r0:
#     - CVE-2020-0499
#     - CVE-2021-0561
#   1.3.2-r2:
#     - CVE-2017-6888

build() {
	export CFLAGS="$CFLAGS -O3 -flto=auto"
	export CXXFLAGS="$CXXFLAGS -O3 -flto=auto"

	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_TESTING=OFF \
		-DBUILD_EXAMPLES=OFF \
		-DBUILD_SHARED_LIBS=ON \
		-DNDEBUG=ON

	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm0644 COPYING.Xiph \
		"$pkgdir"/usr/share/licenses/$pkgname/COPYING.Xiph
}

libs() {
	# purely for backwards compat
	depends="libflac=$pkgver-r$pkgrel libflac++=$pkgver-r$pkgrel"
	mkdir -p "$subpkgdir"
}

libflac() {
	pkgdesc="$pkgdesc (libFLAC)"

	amove usr/lib/libFLAC.so.*
}

libpp() {
	pkgdesc="$pkgdesc (libFLAC++)"

	amove usr/lib/libFLAC++.so.*
}

sha512sums="
3cf095720bd590a588be8ccbe187d22e7a1c60ab85b1d510ce5e8a22ab0a51827b9acfeaad59bbd645a17d1f200f559255a640101b0330709a164306c0e9709e  flac-1.4.3.tar.xz
"
